package com.ai.bitcoin.jpa.dao;

import com.ai.bitcoin.jpa.entity.BccOrder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

public interface BccOrderDao extends JpaRepository<BccOrder, String> {

    BccOrder findByOrderCode(String orderCode);

    /**
     * @Modifying
     @Query("update ShopCoupon sc set sc.deleted = true where sc.id in :ids")
     public void deleteByIds(@Param(value = "ids") List<String> ids);
     1）update或delete时必须使用@Modifying对方法进行注解，才能使得ORM知道现在要执行的是写操作

     2）有时候不加@Param注解参数，可能会报如下异常：
     */
    @Query(nativeQuery = true, value = "update bcc_order set update_time = ?1 ,status = ?2,third_order_code = ?3 where order_code = ?4")
    @Modifying
    void updateOrderByOrderCode(Date now, Integer status, String thirdOrderCode, String orderCode);


    List<BccOrder> findAllByStatusAndTypeAndUserSymbolOrderByUpdateTimeDesc(Integer status, Integer type, String userSymbol);

}
